package com.yushixin.account.controller;

import com.yushixin.account.model.Account;
import com.yushixin.account.service.IAccountService;
import com.yushixin.common.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/accounts")
public class AccountController {
    
    @Autowired
    private IAccountService accountService;
    
    @GetMapping
    public R<List<Account>> findAll() {
        return R.success(accountService.findAll());
    }
    
    @PostMapping
    public R<Void> addAccount(Account account) {
        accountService.addAccount(account);
        return R.success();
    }
    
    @PutMapping
    public R<Void> updateAccount(Account account) {
        accountService.updateAccount(account);
        return R.success();
    }
    
    @DeleteMapping("/{id}")
    public R<Void> deleteAccount(@PathVariable Long id) {
        accountService.deleteAccount(id);
        return R.success();
    }
}